<%@ include file="connect.jsp" %>
<%--
  Created by IntelliJ IDEA.
  User: Mery
  Date: 10/25/12
  Time: 11:03 PM
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    if (session.getAttribute("namaUser") == null) {

        response.sendRedirect("login.jsp?respon=You have to login first!");
    }

%>


<html>
<head>
    <title>Business English</title>
    <link href="style.css" rel="stylesheet"/>
    <script type="text/javascript" language="javascript">
        function confirmAction() {
            var confirmed = confirm("Are you sure want to delete this question?");
            return confirmed;
        }
    </script>
    <script src="jquery.js" type="text/javascript"></script>
    <script src="facebox.js" type="text/javascript"></script>
    <script type="text/javascript">
        jQuery(document).ready(function ($) {
            $('a[rel*=facebox]').facebox({
                loadingImage:'images/loading.gif',
                closeImage:'images/closelabel.png'
            })
        })
    </script>
</head>

<body>
<table id="bg" cellspacing="0">
    <tr id="header">

        <td class="link">
            <%@ include file="header.jsp" %>
        </td>
    </tr>
    <tr id="menu">
        <td>
            <%@ include file="menu.jsp" %>
        </td>
    </tr>
    <tr id="hr">
        <td><hr width="100%" size="8" noshade="noshade" ></td>
    </tr>
    <tr id="content">
        <td class="link" valign="top" style="padding-left: 20px">
            <table>
                <tr id="title">
                    <td>Post Test</td>
                </tr>
                <tr>
                    <td>
                        <div class="btn-fld">
                            <a href="AddNewQuePost.jsp">
                                <button type="button">Add New Question</button>
                            </a></div>
                    </td>
                </tr>
                <table>
                    <tr id="warning">
                        <td>

                            <%
                                String respon = request.getParameter("respon");

                                if (respon != null) {

                                    out.print(respon);
                            %>
                            <% } %>
                        </td>
                    </tr>
                </table>
                <table width="95%" border="2" id="bor1">

                    <tr style="text-align: center; font-weight: 600">
                        <td  width="12px">No</td>
                        <td width="20%">Question's Name</td>
                        <td width="20%">Question's Type</td>
                        <td width="10%">Category</td>
                        <td>Question</td>
                        <td width="10%">Action</td>
                    </tr>
                    <tr>
                        <%

                            String sql = "select count(*) from detailtest a, detailquestion b where a.detailTestID = b.detailTestID and testId =2";
                            ResultSet rs = stat.executeQuery(sql);
                            Integer Record = 0;
                            Integer record1page = 12;
                            if (rs.next()) {
                                Record = Integer.parseInt(rs.getString(1));
                            }
                            String hlm = request.getParameter("Page");
                            int i = 0;
                            Integer off = 0;
                            if (hlm != null) {
                                off = (Integer.parseInt(hlm) - 1) * record1page;
                            }
                            sql = "select * from detailtest a, detailquestion b, styles c, categories d where a.detailTestID = b.detailTestID and b.stylesID = c.stylesID and a.categoryID = d.categoryID and testID = 2 ORDER BY questionID LIMIT " + record1page + " OFFSET " + off;
                            ;
                            rs = stat.executeQuery(sql);
                            Integer maxpage = (int) Math.ceil((double) Record / (double) record1page);
                            while (rs.next()) {
                                i = i + 1;
                                String id = rs.getString("questionID");
                        %>
                        <td><%=i%>
                        </td>
                        <td name=id><%out.print(rs.getString("detailName"));%></td>
                        <td><%out.print(rs.getString("stylesName"));%></td>
                        <td><%out.print(rs.getString("categoryName"));%></td>
                        <td><%out.print(rs.getString("Question"));%></td>
                        <td style="text-align: center"><a href="EditQuePost.jsp?id=<%=id%>" rel="facebox"><img
                                height="25px" src="edit.png" title="Edit Question"></a>
                            <a href="doDeleteQuePost.jsp?id=<%out.print(rs.getString("questionID"));%>&nama=<%out.print(rs.getString("detailName"));%>"
                               onclick="return confirmAction()"><img height="25px" src="Delete.png"
                                                                     title="Delete Question"></a></td>
                    </tr>
                    <% } %>
                </table>

                <table>
                    <tr id="title">
                        <td>Page >></td>
                        <%
                            for (int a = 0; a < maxpage; a++) {

                        %>
                        <td><a href="posttest.jsp?Page=<%=a+1%>"/> <%out.print(a + 1);%></td>
                        <%}%>
                    </tr>
                </table>
            </table>
        </td>
    </tr>

</table>
</body>
</html>